;;(function(){
//     function saveData(type,json){
//         localStorage.setItem(type,JSON.stringify(json));
//   }
//   function getCarts(){
//     if(localStorage.getItem("carts")){
//           return JSON.parse(localStorage.getItem("carts"))
//     }else{
//           return {};
//     }
// }
//购物车
showContent();
async function showContent(){
      var totalPrice = 0;
      html = '';
      let dataList = await $.ajax('./json/kuaizulist.json');
      if(localStorage.length == 0){
            html += `<ul class="cart-list"></ul>`
      }else{
            let data = localStorage;
            for(let attr in data){
                  for(let i = 0 ; i < dataList.list.length ; i++){
                        if(dataList.list[i].id == attr){
                              let price = parseInt(data[attr])*parseInt(dataList.list[i].group_price);
                              totalPrice += price;
                              html += `<ul class="cart-list" data-id='${dataList.list[i].id}'>
                              <li class="li1">
                                  <input class="checked" type="checkbox">
                              </li>
                              <li class="li2">
                                  <div class="goods-imgs"><img src="${dataList.list[i].image_url}" alt=""></div>
                                  <div class="goods-title">${dataList.list[i].title}</div>
                              </li>
                              <li class="li3">¥<span>${dataList.list[i].group_price}</span></li>
                              <li class="li4">${data[attr]}</li>
                              <li class="li5">¥<span>${price}</span></li>
                              <li class="li6">删除</li>
                          </ul>`;
                        }
                  }
            }
      }
      html+=`<div class="cart-account">
      <div class="select">
          <input class="checkedAll" type="checkbox">
          <p>全选  删除选中商品 清空购物车</p>
      </div>
      <div class="money">
          <div>结算</div>
          <p>总金额¥<span>${totalPrice}</span>元</p>
      </div>
  </div>`;
      $('.cart-content').html(html);
      $('.cart-content').on('click','.li6',deleteData);
}
async function deleteData(){
      let id = $(this).parents().attr('data-id');
      localStorage.removeItem(`${id}`);
      var totalPrice = 0;
      html = '';
      let dataList = await $.ajax('./json/kuaizulist.json');
      if(localStorage.length == 0){
            html += `<ul class="cart-list"></ul>`
      }else{
            let data = localStorage;
            for(let attr in data){
                  for(let i = 0 ; i < dataList.list.length ; i++){
                        if(dataList.list[i].id == attr){
                              let price = parseInt(data[attr])*parseInt(dataList.list[i].group_price);
                              totalPrice += price;
                              html += `<ul class="cart-list" data-id='${dataList.list[i].id}'>
                              <li class="li1">
                                  <input class="checked" type="checkbox">
                              </li>
                              <li class="li2">
                                  <div class="goods-imgs"><img src="${dataList.list[i].image_url}" alt=""></div>
                                  <div class="goods-title">${dataList.list[i].title}</div>
                              </li>
                              <li class="li3">¥<span>${dataList.list[i].group_price}</span></li>
                              <li class="li4">${data[attr]}</li>
                              <li class="li5">¥<span>${price}</span></li>
                              <li class="li6">删除</li>
                          </ul>`;
                        }
                  }
            }
      }
      html+=`<div class="cart-account">
      <div class="select">
          <input class="checkedAll" type="checkbox">
          <p>全选  删除选中商品 清空购物车</p>
      </div>
      <div class="money">
          <div>结算</div>
          <p>总金额¥<span>${totalPrice}</span>元</p>
      </div>
  </div>`;
      $('.cart-content').html(html);
}

})(jQuery);